import requests

from common.log_util import init_logger
from config import BASE_URL

logger = init_logger()


class EmployeeApi(object):
    path = "/api/sys/user"

    @classmethod
    def add_emp(cls, headers, body):
        url = BASE_URL+cls.path
        logger.debug(f"URL:{url}")
        logger.debug(f"headers:{headers}")
        logger.debug(f"body:{body}")
        resp = requests.post(url=url, headers=headers, json=body)
        logger.debug(f"resp:{resp.json()}")
        return resp

    @classmethod
    def query_emp(cls, headers, user_id):
        url = BASE_URL + cls.path + "/" + user_id
        logger.debug(f"URL:{url}")
        logger.debug(f"headers:{headers}")
        resp = requests.get(url=url, headers=headers)
        logger.debug(f"resp:{resp.json()}")
        return resp

    @classmethod
    def modify_emp(cls, headers, body, user_id):
        url = f"{BASE_URL}{cls.path}" + "/" + user_id
        logger.debug(f"URL:{url}")
        logger.debug(f"headers:{headers}")
        logger.debug(f"body:{body}")
        resp = requests.put(url=url, headers=headers, json=body)
        logger.debug(f"resp:{resp.json()}")
        return resp

    @classmethod
    def del_emp(cls, headers, user_id):
        url = f"{BASE_URL}{cls.path}" + "/" + user_id
        logger.debug(f"URL:{url}")
        logger.debug(f"headers:{headers}")
        resp = requests.delete(url=url, headers=headers)
        logger.debug(f"resp:{resp.json()}")
        return resp
